package com.atguigu.lease.common.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chengke
 * @version 1.0
 * @className MinioConfiguration
 * @description minio配置类
 * @date 2024/8/2 22:26
 */
@Configuration
@EnableConfigurationProperties(MinioProperties.class)//单个注册
//@ConfigurationPropertiesScan("com.atguigu.lease.common.minio")//注册整个包下的
//当"minio.endpoints"属性存在时，该配置类才生效
@ConditionalOnProperty(name="minio.endpoint")
public class MinioConfiguration {

    @Autowired
    private MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder().endpoint(minioProperties.getEndpoint()).credentials(minioProperties.getAccessKey(),minioProperties.getSecretKey()).build();
    }

}